package at.fhooe.mc.duel_game;

import android.os.Parcel;
import android.os.Parcelable;

public class DuelResult implements Parcelable {
	private final String mPlayerName;
	private final long mMyTime;
	private final long mOpponentTime;
	private final boolean[] mWin = new boolean[1];

	public DuelResult(String playerName, long myTime, long opponentTime) {
		mPlayerName = playerName;
		mMyTime = myTime;
		mOpponentTime = opponentTime;
		mWin[0] = (myTime <= opponentTime) ? true : false;
	}

	public String getPlayer() {
		return mPlayerName;
	}

	public long getMyTime() {
		return mMyTime;
	}
	
	public long getOpponentTime() {
		return mOpponentTime;
	}

	public boolean isWin() {
		return mWin[0];
	}

	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	public void writeToParcel(Parcel out, int arg1) {
		out.writeString(mPlayerName);
		out.writeBooleanArray(mWin);
		out.writeLong(mMyTime);
		out.writeLong(mOpponentTime);
	}

	// this is used to regenerate your object. All Parcelables must have a
	// CREATOR that implements these two methods
	public static final Parcelable.Creator<DuelResult> CREATOR = new Parcelable.Creator<DuelResult>() {
		public DuelResult createFromParcel(Parcel in) {
			return new DuelResult(in);
		}

		public DuelResult[] newArray(int size) {
			return new DuelResult[size];
		}

	};

	// example constructor that takes a Parcel and gives you an object populated
	// with it's values
	private DuelResult(Parcel in) {
		mPlayerName = in.readString();
		in.readBooleanArray(mWin);
		mMyTime = in.readLong();
		mOpponentTime = in.readLong();
	}

}
